package com.guo.cmn.controller;

import com.guo.cmn.service.DictService;
import com.guo.common.result.Result;
import com.guo.model.cmn.Dict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author gfj
 * @Date 2022/1/18 11:58
 */
@RestController
@Api("数据字典接口")
@Slf4j
@RequestMapping("/admin/cmn/dict")
@CrossOrigin
public class DictController {
	@Autowired
	private DictService dictService;
	@ApiOperation("查询数据字典")
	@GetMapping("/findChildData/{id}")
	public Result findChildData(@PathVariable("id")long id){
		List<Dict> list= dictService.findChildData(id);
		Result<List> result = new Result<>();
		result.setData(list);
		result.setCode(200);
		result.setMessage("成功");
		return result;
	}
	@ApiOperation("导出dict数据")
	@GetMapping("/exportDictData")
	public void exportDictData(HttpServletResponse response){
		dictService.exportDictData(response);
	}

	@ApiOperation("导入dict数据")
	@PostMapping("/importDictData")
	public Result importDictData(MultipartFile file) {
		dictService.importDictData(file);
		return Result.ok();
	}
}